﻿using System;
using System.Web.UI;

using BizElements.BusinessLayer;

namespace BizElements.Web
{
    /// <summary>Represents the simple binding between the field value of an object and the property value of a control.</summary>
    sealed class FieldBinding : IFieldBinding
    {
        /// <summary>Initializes a new instance of FieldBinding class.</summary>
        /// <param name="field">Business object's field.</param>
        /// <param name="boundControl">Bound control to which the field is bound that supports advanced binding features.</param>
        public FieldBinding(IBindableField field, IBoundControl boundControl)
        {
            if (field == null)
                throw new ArgumentNullException("field");
            if (boundControl == null)
                throw new ArgumentNullException("boundControl");

            this.Field = field;
            this.BoundControl = boundControl;
            this.ErrorLabel = boundControl.ErrorLabel;
            this.CaptionLabel = boundControl.CaptionLabel;
            this.TooltipLabel = boundControl.TooltipLabel;
        }

        /// <summary>Gets business object's field.</summary>
        public IBindableField Field { get; private set; }
        
        /// <summary>Gets bound control to which the field is bound that supports advanced binding features.</summary>
        public IBoundControl BoundControl { get; private set; }

        /// <summary>Gets or sets optional error label control which displays errors associated with the given field. May be embedded in bound control, or it may a stand-alone control.</summary>
        public ITextControl ErrorLabel { get; set; }

        /// <summary>Gets or sets optional caption label control which contains field caption/title. May be embedded in bound control, or it may a stand-alone control.</summary>
        public ITextControl CaptionLabel { get; set; }

        /// <summary>Gets or sets optional control which contains additional control info. May be embedded in bound control, or it may a stand-alone control.</summary>
        public ITextControl TooltipLabel { get; set; }

        /// <summary>Gets or sets optional control that indicates whether a field is required. May be a picture control, a label control with asterisk etc.</summary>
        public Control RequiredFieldIndicatorControl { get; set; }
    }
}